import 'reflect-metadata'
const RR=Reflect as any;
console.log(999,RR);

function Container(path:string) {
  return function (target: any) {
    RR.defineMetadata('path',path,target)
  };
}
function methodDec(method: string) {
  return function (path: string) {
    return function (target: any, key: any,describe:any) {
        RR.defineMetadata('method',method,describe.value)
        RR.defineMetadata('path',path,describe.value)
    };
  };
}
const Post = methodDec("post");
const Get = methodDec("get");
const Delete = methodDec("delete");
@Container('artcile')
class ArticleContainer {
  @Post("/add")
  addArticle() {}

  @Get("/get")
  getArticle() {}

  @Delete("/delete")
  deleteArticle() {}
}
const articleContainer=new ArticleContainer()
function creatRoutes(container:any){
    const prototype:any=RR.getPrototypeOf(container)
    const classPath=RR.getMetadata('path',prototype.constructor)
    const keys=RR.ownKeys(prototype).filter((item:any)=>item!=="constructor");
    const routes:any[]=[]
    keys.forEach((key:any) => {
        const fn=prototype[key];
        const method=RR.getMetadata('method',fn)
        const path=RR.getMetadata('path',fn)
        routes.push({method,path:classPath+path,handler:fn})
    });
    return routes;

}
const routes=creatRoutes(articleContainer)
console.log(66,routes);


export {};
